<?php

include_once('deplacelayout.class.php');
include_once('myPDO.class.php');

class DeplaceLayoutDAO {

    // Création du layout 
    public function createDeplaceLayout(/* DeplaceLayout */ $gridLayout, /* myPDO */ $db) {

        try {
            $stmt = $db->prepare("INSERT INTO DeplaceLayout (nbItems, Activite_idActi) VALUES (:items, :ida)");
            $items = $gridLayout->getNbItems();
            $id_acti = $gridLayout->getActiId();

            $stmt->bindParam(':items', $items);
            $stmt->bindParam(':ida', $id_acti);

            $stmt->execute();
            
        } catch (Exception $e) {
            echo 'Exception re�ue : ', $e->getMessage(), "\n";
        }
    }
    
    // Trouver un layout appartenant à une activité
    public function findDeplaceLayout(/* Layout */ $layout, /* myPDO */ $db) {
        $stmt = $db->prepare("SELECT * FROM DeplaceLayout WHERE Activite_idActi = :id ;");
        $id = $layout->getActiId();
        $stmt->bindParam(':id', $id);
        $res = $stmt->execute();
        $row = $stmt->fetchObject();
        if ($row == null) {
            return null;
        } else {
            //print_r($row);
            $layout = new DeplaceLayout($row->identifiant, $row->nbItems, $row->Activite_idActi);
            return $layout;
        }
    }
    
    // Spprimer un Grid Layout appartenant à une activité
    public function deleteDeplace(/* Layout */ $layout, /* myPDO */ $db) {
        try {
            $stmt = $db->prepare("DELETE FROM DeplaceLayout WHERE Activite_idActi = :id ;");
            $id = $layout->getActiId();
            $stmt->bindParam(':id', $id);
            $stmt->execute();
        } catch (Exception $e) {
            echo 'Exception re�ue : ', $e->getMessage(), "\n";
        }
    }

}

?>